package com.elvin.usingbc;

import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.os.Build;

public class MainActivity extends Activity {

	private Button btnSendBroadcast;
	private Button btnRegBCR;
	private Button btnUnRegBCR;
	
	
	private final MyBC mybc = new MyBC();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		btnSendBroadcast = (Button) findViewById(R.id.btnSendBroadcast);
		btnRegBCR = (Button) findViewById(R.id.btnRegBCR);
		btnUnRegBCR = (Button) findViewById(R.id.btnUnRegBCR);
		
		
		btnSendBroadcast.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
//				Intent i = new Intent(MainActivity.this, MyBC.class);
				
				Intent i = new Intent(MyBC.ACTION);
				i.putExtra("txt", "hello elvin");
				//启动Broadcast,发送广播
				sendBroadcast(i);
			}
		});
		
		btnRegBCR.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				registerReceiver(mybc, new IntentFilter(MyBC.ACTION));
			}
		});
		
		btnUnRegBCR.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				unregisterReceiver(mybc);
			}
		});
		
		
		
	}

}
